#include "rbmpgeneratorsync.h"
#include "imagematrix.h"
#include "eightlayerim.h"
#include "bitmap.h"


RBMPGeneratorSync::RBMPGeneratorSync()
{
	randomize();
}

void RBMPGeneratorSync::randomize()
{
		int period = 2 + (rand() % (MCOLS-2));
		pixelValue.clear();
		for (int valueCounter = 0; valueCounter < period; ++valueCounter)
			pixelValue.push_back(rand() % GRAYCALE_LEVELS);
}

void RBMPGeneratorSync::draw (std::string filename)
{
	try
	//create 8 imagematrices and combine them to an ELIM
	{
		CBitmap resultBMP (filename);
		int rowNum = resultBMP.GetHeight();
		int colNum = resultBMP.GetWidth();
		assert (colNum == MCOLS && rowNum == MROWS);

		int period = (int) pixelValue.size();
		int serialCounter = 0;
		for (int row = 0; row < MROWS; ++row)
			for (int col = 0; col < MCOLS; ++col)
				resultBMP.setGrayRC(pixelValue[serialCounter++ % period], row,col);
		resultBMP.Save(filename); 
	}
	catch (exception e)
	{
		cerr << e.what();
	}

}

